package org.friping.mytool.views.custom.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import org.androidannotations.annotations.AfterInject;
import org.androidannotations.annotations.EBean;
import org.androidannotations.annotations.RootContext;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/*
 * app base adpater the sub adapter should use @Ebean to injector
 */
@EBean
public class AppAdapter extends BaseAdapter {
    protected List<Map> data = new ArrayList();
    protected LayoutInflater inflater = null;


    @RootContext
    Context context;

    @AfterInject
    void initAdapter(){
        this.inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        return null;
    }

    public void addItem(Map map){
        this.data.add(map);
        this.notifyDataSetChanged();
    }
    public void removeItem(Integer pos){
        this.data.remove(getItem(pos));
        this.notifyDataSetChanged();
    }

    public void addList(List list) {
        this.data.addAll(list);
        this.notifyDataSetChanged();
    }

    public void refresh(List<Map> data){
        this.data.clear();
        this.data.addAll(data);
        this.notifyDataSetChanged();
    }

}